home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ8801.ZIP / NARO.ZIP / BOOT.C next >
Text File  |  1987-10-30  |  2KB  |  76 lines

  1. /*
  2.     Copyright (C) 1987 Paradigm Systems Inc.  All rights reserved.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <io.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <malloc.h>
  10.  
  11. #include "loc.h"
  12. #include "externs.h"
  13.  
  14.  
  15. void    create_bootstrap(seg_list, entry)
  16. SEG_DESCRIPTOR    *seg_list ;
  17. unsigned char    *entry ;
  18. {
  19.     unsigned int    count ;
  20.     unsigned char    *ptr ;
  21.  
  22.     SEG_DESCRIPTOR *p, *q ;
  23.  
  24.     /*
  25.         This function sets up a new class which contains the bootstrap
  26.         code to the program entry point.  The bootstrap segment is
  27.         always located at physical address FFFF0H is ROMable.
  28.         
  29.         The bootstrap record is appended to the load module for the
  30.         purpose of locate processing.
  31.     */
  32.  
  33.     /* Traverse the linked list to the end */
  34.     p = seg_list ;
  35.     while (p->next != NULL)
  36.         p = p->next ;
  37.  
  38.     /* Allocate the memory for the bootstrap record */
  39.     if ((q = (SEG_DESCRIPTOR *) malloc(sizeof (*p))) == NULL)  {
  40.         perror(__FILE__) ;
  41.         exit(1) ;
  42.     }
  43.  
  44.     /* Append the bootstrap record to the end of the list */
  45.     p->next = q ;
  46.  
  47.     /* Initialize the bootstrap segment descriptor */
  48.     strcpy(q->name, "??BOOT") ;
  49.     strcpy(q->class, "(ABSOLUTE)") ;
  50.     q->vseg = 0xffff ;
  51.     q->pseg = 0xffff ;
  52.     q->offset = 0x0000 ;
  53.     q->len = 5 ;
  54.     q->inited = TRUE ;
  55.     q->romable = TRUE;
  56.     q->symbols = 0 ;
  57.     q->symbol_list = NULL ;
  58.     q->next = NULL ;
  59.  
  60.     /* Allocate RAM and build the reset vector code using a far jump */
  61.     ptr = malloc(q->len) ;
  62.     *ptr = 0xEA ;
  63.     *((unsigned char **)(ptr + 1)) = entry ;
  64.  
  65.     /* Append the bootstrap code on tail of the load module */
  66.     q->position = lseek(tmp_file, 0L, SEEK_END) ;
  67.     count = write(tmp_file, ptr, q->len) ;
  68.     if (count != q->len)   {
  69.         perror(__FILE__) ;
  70.         exit(1) ;
  71.     }
  72.  
  73.     free(ptr) ;
  74.     return ;
  75. }
  76.